package com.qdlc.p2p.dal.dao.impl;

import java.util.List;

import javax.persistence.Query;

import org.springframework.stereotype.Repository;

import com.qdlc.p2p.dal.common.dao.jpa.BaseDaoImpl;
import com.qdlc.p2p.dal.dao.UserSignDao;
import com.qdlc.p2p.dal.dto.UserSign;

/**
 * Created by liaoxiangkai on 2015/11/10.
 */
@Repository("userSignDao")
public class UserSignDaoImpl extends BaseDaoImpl<UserSign> implements UserSignDao {

    @SuppressWarnings("unchecked")
    public UserSign findLastRecord(long userId) {
        String jpql = " from UserSign where userId = :userId ORDER BY id desc LIMIT 0,1";
        Query query = em.createQuery(jpql);
        query.setParameter("userId", userId);
        List<UserSign> list = query.getResultList();
        return list != null && list.size() >0 ? list.get(0) : null;
    }
}
